package com.qf.openapi.web.master.intercepter;

import com.qf.openapi.web.master.entity.User;
import com.qf.openapi.web.master.vo.TableVo;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.util.Optional;

public class UserIntercepter implements HandlerInterceptor {

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {

//        System.out.println("123");
        HttpSession session = request.getSession();
        User user = (User) session.getAttribute("user");
        if (Optional.ofNullable(user).isPresent()){
            return true;
        }

        response.sendRedirect("/login.html");
        return false;
    }


}
